package 笔试.HF;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author:谢君臣
 * @Date:2021/7/24-19:48
 * @version:1.0
 * @function:
 */
public class HF_DD3 {
    private static volatile int num = 0;

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        List<Callable<Integer>> tasks = new ArrayList<>();

        for (int i = 0; i < 8; i++) {
            Callable<Integer> task = () -> {
                for (int times = 0; times < 100; times ++) {
                    num += 1;
                }
                return num;
            };
            tasks.add(task);
        }
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        List<Future<Integer>> futureResults = executorService.invokeAll(tasks);
        for (Future<Integer> futureResult : futureResults) {
            System.out.println(futureResult.get());
        }
        System.out.println(num);
    }
}
